#include<iostream>
#include<unistd.h>
#include<signal.h>
#include<sys/types.h>
#include<sys/wait.h>

using namespace std;

void fun(int signo){
  cout<<"segmentfault error:"<<signo<<endl;
  exit(11);
}

void FUN(int signo){
  cout<<"I am alram:"<<signo<<endl;
  int n=alarm(5);
  cout<<"tiem:"<<n<<endl;
}

int main(){
  pid_t id=fork();
  if(id==0){
    int cnt=10000;
    while(cnt--){
      cout<<"I am child process: pid :"<<getpid()<<endl;
      sleep(1);
    }
  }
  sleep(3);
  // int a=10/0;
   int status=0;
  int ret=waitpid(-1,&status,0);
  if(ret==id){
      cout<<"wait success"<<endl;
      cout<<"exit_signale:"<<(status&0x7F)<<endl<<"exit_core:"<<\
      ((status>>7)&1)<<endl<<"exit_code:"<<((status>>8)&0xFF)<<endl;
  }











  // signal(SIGALRM,FUN);
  // int n=alarm(300);
  // while(1){
  //   sleep(1);
  //   cout<<"heheeeeeeheh"<<endl;
  // }

  // signal(SIGSEGV,fun);
  // int* p=nullptr;
  // *p=10;
  return 0;
}
